package dht.data;

import java.util.Vector;

import dht.simulation.GlobalVariables;

public class Access {
	public int accessId;
	public AccessType accessType;
	public double startTime;
	public int requesterId;
	public String fileName;
	public int fileSize;
	public int msgSent;

	public Vector<Message> messageFlow;

	public Access() {
		accessId = 0;
		accessType = null;
		startTime = 0.0;
		requesterId = 0;
		fileName = null;
		fileSize = 0;
		msgSent = 0;
		messageFlow = new Vector<Message>();
	}

	public boolean valid() {

		// double prevTime = startTime;
		// for (Message msg : messageFlow) {
		// if (!equal(msg.generateTime, prevTime)) {
		// return false;
		// }
		// prevTime = msg.getCurrentTime();
		// }
		return true;
	}

	public static boolean equal(double a, double b) {
		return Math.abs(a - b) < GlobalVariables.eps;
	}

	public String toString() {
		String value = "###Access begin###\naccessId: " + accessId
				+ " accessType: " + accessType + " startTime: " + startTime
				+ " requesterId: " + requesterId + " fileName: " + fileName
				+ " fileSize: " + fileSize + " msgSent: " + msgSent
				+ " messageFlowSize: " + messageFlow.size() + "\n";
		for (Message msg : messageFlow) {
			value += msg.toString();
		}
		value += "###Access end###\n";
		return value;
	}

	public void dump() {
		System.out.println(toString());
	}
}
